<?php
	class Sutri_model extends Model{
		function Sutri_model(){
			parent::Model();
		}
        
        function list_data($nip="",$where="", $order="", $ro=false) {     
        	if ($nip=="") {
        		return "";
        	} else {
                $this->db->where(array('nip' => $nip));
                $this->db->or_where(array('nip_baru' => $nip));
        	}
        	
            if ($where!='') {
                $this->db->where($where);
            }
            if ($order == "") {
                $this->db->order_by('nip asc');
                $this->db->order_by('nip_baru asc');
            } else {
                $this->db->order_by($order);
            }
            $this->db->from('pegawai');
            $q = $this->db->get();

            $s = "
              <table id=\"scrollable\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"tbl\">
                <thead>
                  <tr>
                    <th>No</th>
                    <th>Nama</th>
                    <th>Tempat Lahir</th>
                    <th>Tgl Lahir</th>
                    <th>Pekerjaan</th>
                    <th>Pendidikan</th>
                    <th>Tgl Nikah</th>
                    <th>Status Tunjangan</th>
                    ";
            if ($ro==false) {
                $s .= " <th colspan='2'> Aksi </th>";
            }
            $s .= "</tr></thead><tbody>";
			$i = 1;

            $this->load->model('Datum_model');
            foreach($q->result() as $row) {
                if ($i % 2 == 1) {
                    $kelas = "event2";
                } else {
                    $kelas = "event";
                }
                
                $this->db->where(array('id_pegawai' => $row->idspg_pegawai));                
                $q1 = $this->db->get('suami_istri');
                if ($q1->num_rows() > 0) {
                	foreach ($q1->result() as $row1) {
		               
		                
		                $s .= "
                        
		              <tr class=\"$kelas\" id=\"row-".$row1->id_suami_istri."\" >
		                <td><div align=\"right\">$i.&nbsp;&nbsp;&nbsp;</div></td>
		                <td>".$row1->nama."</td>
		                <td>".$row1->tempat_lahir."</td>
		                <td>".YMD2DMY(trimTime($row1->tgl_lahir), TGL_SEPARATOR)."</td>
		                <td>".$row1->pekerjaan."</td>
                        <td>".$row1->pendidikan."</td>
                        <td>".YMD2DMY(trimTime($row1->tgl_nikah), TGL_SEPARATOR)."</td>
                        <td>".$row1->status_tunjangan."</td>
                        ";
		                if ($ro==false) {
		                    $s .= "
		                    <td><div align='center'> <a href='".base_url()."index.php/suami_istri/form_edit/".$row1->id_suami_istri."' title=\"Ubah Data\" class=\"edit\"><img src='".base_url()."images/edit.gif' border='0'></a></div></td>";
                           // if($this->input->post('page'))   
		                    $s .= "<td><div align='center'><a href=\"javascript:deleteRow(".$row1->id_suami_istri.")\"><img src='".base_url()."images/del.gif' border='0'></a></div></td>";
		                }
		                $s .= "
		              </tr>";
		
		                $i++;
                	} //foreach
                } else {
                	continue;
                }

            }
            $s .= "</tbody></table>";
            return $s;
        }

        function entry_data($form_id, $form_action, $arr=array()) {
            //format tgl_ijazah harus YMD
            if (isset($arr['tgl_lahir'])) {
                $a = explode(TGL_SEPARATOR, trimTime($arr['tgl_lahir']));
                $d = $a[2] * 1;
                $m = $a[1] * 1;
                $y = $a[0];
            } else {
                $d = date("j");
                $m = date("n");
                $y = date("Y");
            }
            if (isset($arr['tgl_nikah'])) {
                $a = explode(TGL_SEPARATOR, trimTime($arr['tgl_nikah']));
                $dn = $a[2] * 1;
                $mn = $a[1] * 1;
                $yn = $a[0];
            } else {
                $dn = date("j");
                $mn = date("n");
                $yn = date("Y");
            }
            $foto = (!empty($arr['foto']))?"<img src='".base_url()."arsip/".$arr['id_pegawai']."/".$arr['foto']."'  width='128px'><br /><center>".anchor('/suami_istri/hapus_foto/'.$arr['id_suami_istri'],'[x]hapus')."</center>":'';
            $ret = "
            <form id=\"".$form_id."\" action=\"".$form_action."\" enctype=\"multipart/form-data\" method=\"post\">
            <fieldset >
            <table class=\"formTabel\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\">
              <tr>
                <td class=\"kolom\" valign=\"top\">NIP</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"nip\" id=\"nip\" value=\"".(isset($arr['nip'])?$arr['nip']:$this->session->userdata('nip'))."\" /></td>
              </tr>
              <tr>
                <td class=\"kolom\" valign=\"top\"></td>
                <td valign=\"top\"></td>
                <td valign=\"top\"></td>
                <td valign=\"top\" rowspan='7'><div style='float:right'> $foto </div></td>
              </tr>
              <tr>
                <td class=\"kolom\" valign=\"top\">Foto</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"file\" name=\"foto\" id=\"foto\" size=\"22\" /></td>
              </tr>
                
              <tr>
                <td class=\"kolom\" valign=\"top\">Nama</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[nama]\" size=\"50\" value=\"".(isset($arr['nama'])?$arr['nama']:"")."\" /></td>
              </tr>
              <tr>
                <td class=\"kolom\" valign=\"top\">Tempat Lahir</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[tempat_lahir]\" size=\"50\" value=\"".(isset($arr['tempat_lahir'])?$arr['tempat_lahir']:"")."\" /></td>
              </tr>
              <tr>
                  <td class='fieldname' valign=\"top\">Tanggal Lahir</td>
                <td valign=\"top\">:</td>
                <td>".combo_tanggal('d',$d,'')."-".
                      combo_bulan('m',$m,'').
                      "-<input name='y' id='y' type='text' size='6' value='$y'/>
                        <a href=\"#\" id=\"date-pick\">Pilih Tanggal</a>       
                </td>
              </tr>
              
              <tr>
                <td class=\"kolom\" valign=\"top\">Pekerjaan</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" size=\"38\" name=\"data[pekerjaan]\" value=\"".(isset($arr['pekerjaan'])?$arr['pekerjaan']:"")."\" /></td>
              </tr>
              
              <tr>
                <td class=\"kolom\" valign=\"top\">Pendidikan</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\">".combo_jenjang_pendidikan('data[pendidikan]', (isset($arr['pendidikan'])?$arr['pendidikan']:""))."</td>
              </tr>
              <tr>
                  <td class='fieldname' valign=\"top\">Tanggal Nikah</td>
                <td valign=\"top\">:</td>
                <td>".combo_tanggal('dn',$dn,'')."-".
                      combo_bulan('mn',$mn,'').
                      "-<input name='yn' id='y' type='text' size='6' value='$yn'/>
                        <a href=\"#\" id=\"date-pick\">Pilih Tanggal</a>       
                </td>
              </tr>
              
              <tr>
                <td class=\"kolom\" valign=\"top\">Status Tunjangan</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"radio\" name=\"data[status_tunjangan]\"  value=\"Dapat\" ".(isset($arr['status_tunjangan'])?$arr['status_tunjangan'] == 'Dapat'?'checked="checked"':"":"")." /> Aktif
                <input type=\"radio\" name=\"data[status_tunjangan]\"  value=\"Tidak\" ".(isset($arr['status_tunjangan'])?$arr['status_tunjangan'] == 'Tidak'?'checked="checked"':"":"")." /> Tidak Aktif</td>
              </tr>
              
              <tr>
                <td valign=\"top\">&nbsp;</td>
                <td valign=\"top\">&nbsp;</td>
                <td valign=\"top\">
                  <input class=\"tombol\" type=\"button\" name=\"btn_kembali\" id=\"btn_kembali\" value=\"<< Kembali\" />
                  <input class=\"tombol\" type=\"submit\" name=\"button\" id=\"button\" value=\"   Simpan   \" />
                </td>
              </tr>
            </table>
            </fieldset>
            </form>
              ";
            
            return $ret;
        }

        function simpan($arr, $is_update=false, $id='') {
            if (!$is_update) {
                $this->db->insert('suami_istri', $arr);
                
            } else {
                $this->db->where('id_suami_istri', $id);
                $this->db->update('suami_istri', $arr);
            }
        }
        
	}
?>